/**
 * Copyright (c) 2015 www.smarthome.com All rights reserved. <br />
 * 本软件源代码版权归xxxx公司,未经许可不得任意复制与传播.<br />
 *
 */
package com.smarthome.core.deviceManager.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.smarthome.base.service.ShEquipmentDevCameraService;
import com.smarthome.base.service.ShEquipmentDevIpcService;
import com.smarthome.base.service.ShEquipmentDevSwingService;
import com.smarthome.base.service.ShEquipmentDevTalkService;
import com.smarthome.core.deviceManager.EquipmentDevIpcService;
import com.smarthome.domain.bean.ShEquipmentDevIpc;
import com.smarthome.domain.bean.ShEquipmentDevTalk;
import com.smarthome.domain.vo.boss.DataGrid;
import com.smarthome.domain.vo.boss.PageHelper;

@Service("equipmentDevIpcService")
public class EquipmentDevIpcServiceImpl implements EquipmentDevIpcService {

    @Resource
    private ShEquipmentDevIpcService shEquipmentDevIpcService;
    @Resource
    private ShEquipmentDevCameraService shEquipmentDevCameraService;
    @Resource
    private ShEquipmentDevSwingService shEquipmentDevSwingService;
    @Resource
    private ShEquipmentDevTalkService shEquipmentDevTalkService;

    @Override
    public void updateInternetIp(String mac, String internetIp) {
        ShEquipmentDevIpc ipc = new ShEquipmentDevIpc();
        ipc.setCode(mac);
        List<ShEquipmentDevIpc> ipcs = shEquipmentDevIpcService.selectEntryList(ipc);
        if (null != ipcs && ipcs.size() > 0) {
            // 更新工控机外网ip
            ShEquipmentDevIpc tempEquipmentDevIpc = ipcs.get(0);
            long residenceId = tempEquipmentDevIpc.getResidenceId();
            ShEquipmentDevIpc shEquipmentDevIpc = new ShEquipmentDevIpc();
            shEquipmentDevIpc.setResidenceId(residenceId);
            shEquipmentDevIpc.setInternetIp(internetIp);
            shEquipmentDevIpcService.updateByResidenceId(shEquipmentDevIpc);
            // 更新对讲外网ip
            ShEquipmentDevTalk shEquipmentDevTalk = new ShEquipmentDevTalk();
            shEquipmentDevTalk.setResidenceId(residenceId);
            shEquipmentDevTalk.setInternetIp(internetIp);
            shEquipmentDevTalkService.updateByResidenceId(shEquipmentDevTalk);
        }
    }

    @Override
    public DataGrid dataGrid(ShEquipmentDevIpc devIpc, PageHelper page) {
        return shEquipmentDevIpcService.queryDataGrid(devIpc, page);
    }

    @Override
    public void saveOrUpdate(ShEquipmentDevIpc devIpc) {
        shEquipmentDevIpcService.saveOrUpdate(devIpc);
    }

    @Override
    public ShEquipmentDevIpc queryIpcById(Long id) {
        return shEquipmentDevIpcService.selectEntryById(id);
    }

    @Override
    public int delete(Long id) {
        return shEquipmentDevIpcService.deleteByIds(id);
    }

    @Override
    public List<ShEquipmentDevIpc> getAllList(ShEquipmentDevIpc ipc) {
        return shEquipmentDevIpcService.selectEntryList(ipc);
    }
}
